#Program: String Echo
#code is download from Dr. Thomas W Bennet's website, modified by CJ 2012/2/2
	.text
        .globl  main
main:
# Save registers.
        subu    $sp, $sp, 4             # Make room on the stack.
        sw      $ra, 0($sp)             # Save the return address.
        
# Request a string.
        # Issume a prompt and read a string.
        addiu   $v0, $zero, 4           # Print prompt string.
	lui	$a0, %hi(pr1)
	ori	$a0, %lo(pr1)        
        syscall
        addiu   $v0, $zero, 8           # Read string.
	lui     $a0, %hi(buf)		# Buffer                
	ori     $a0, $a0, %lo(buf)
	addiu	$a1, $zero, 200		#Length of buffer        
        syscall

# Print the messages and the string
        addiu   $v0, $zero, 4           
	lui	$a0, %hi(pr2)
	ori	$a0, %lo(pr2)        
        syscall
        addiu   $v0, $zero, 4           
	lui     $a0, %hi(buf)
	ori     $a0, $a0, %lo(buf)
        syscall
        addiu   $v0, $zero, 4           
	lui     $a0, %hi(msg)
	ori     $a0, $a0, %lo(msg)
        syscall

        # Return
        lw      $ra, 0($sp)             # Restore the return address.
        addu    $sp, $sp, 4             # Pop the stack
        jr      $ra

        .data
# String constants for messages.
pr1:    .asciiz "Please enter a string: "
pr2:    .asciiz "You entered: "
msg:    .asciiz "Congratulations, SPIMmer!\n"

# Space for the input string.
buf:    .space  200
